<?php
/**上傳檔案class
 * 
 * @author hyn
 *
 */
class Uploader
{	
	/**
	 * @var array 副檔名
	 */
	private $ext = array(".csv");
	/**
	 * 
	 */
	private $fileName;
	/**
	 * @var integer 檔案大小
	 */
	private $fileSize;
	/**
	 * @var array 上傳檔案
	 */
	private $uploadFile;
	/**
	 * @var string 檔案放置處
	 */
	private $place = "uploads/";
	/**
	 * 
	 */
	private $maxSize=0;
	/**
	 * 
	 */
	private $tmpName="";
	/**
	 * @var integer 最大上傳數量
	 */
	private $uploadNums = 0;
	/**
	 * @method void 預設建構子
	 */
	public function __construct()
	{		
	}
	/**
	 * @method void 設定上傳副檔名
	 */
	public function setExtention($ext)
	{		
	}
	/**
	 * @method void 設定上傳檔案大小
	 */
	public function setFileSize($size)
	{		
		$this->fileSize = $size;
		//echo $size;
	}
	/**
	 * @method void 設定最大上傳數量
	 */
	public function setUploadNums($nums = 0)
	{		
		$this->uploadNums = $nums;
	}
	/**
	 * @method void 設定上傳檔案放置位置
	 */
	public function setFilePlace($place)
	{		
		$this->place = $place;
	}
	/**
	 * @method void 設定要上傳的檔案
	 * @param int $mode=2代表處理多檔案
	 * @param string $fileName 代表上傳的檔案名稱
	 */
	public function setUploadFile($file,$mode,$fileName)
	{	
		if($mode == 2)
		{			
		}
		else
		{				
			$this->uploadFile = $file;
			$this->fileName = $fileName;			
			//var_dump($this->uploadFile);
		}
	}
	/**
	 * @method bool 執行上傳檔案
	 */
	public function upload()
	{
		//echo $this->tmpName." ".$this->place." ".$this->fileName;
		return move_uploaded_file($this->tmpName,$this->place.$this->fileName);
	}
	/**
	 * @method bool 確認是否為合法副檔名
	 */
	public function isValidExt($fileExt)
	{
		if(in_array($fileExt,$this->ext))
		{
			return false;//副檔名不合法
		}
		else
		{
			return true;
		}
	}
	public function setMaxFileSize($size)
	{
		//$size單位為MB		
		$this->maxSize = $size*1024;
	}
	public function getFileExt($fileName)
	{
		return $ext = strrchr($fileName,".");
	}
	public function setTmpFile($tmpName)
	{
		$this->tmpName = $tmpName;		
	}	
}
?>
